﻿@inherits AdminCompontentBase
<SSimpleModal Value="_visible" ValueChanged="HandleVisibleChanged" OnDelete="HandleDel" OnSave="HandleOk"
              Title="@T(_entityId == default?"AddWebHook":"EditWebHook")" Class="full-height" HeaderClass="mr-4">
    <ChildContent>
        <MForm Model="_model" EnableValidation @ref="_form" Class="full-height">
            <AutoHeight>
                <AutoHeightContent>
                    <div class="d-flex align-center mb-n3">
                        <span class="btn regular2--text flex-shrink-0">@T("SecretKey")</span>
                        <MenuTooltip Class="ml-1 mt-n1" Tooltip="@T("SecretKeyTips")" />
                        <PCopyableText Class="d-flex justify-space-between full-width ml-6" TooltipClass="display-none">
                            <span class="emphasis--text h8">@_model.SecretKey</span>
                        </PCopyableText>
                        <MSpacer></MSpacer>
                        <MButton Class="ml-6" Icon OnClick="HandleRefresh">
                            <SIcon Size=20 Color="emphasis2">mdi-refresh</SIcon>
                        </MButton>                 
                    </div>
                    <STextField Class="mt-9" @bind-Value="_model.DisplayName" Label="@T(nameof(_model.DisplayName))"></STextField>
                    <STextField Class="mt-9" @bind-Value="_model.Url" Label="@T(nameof(_model.Url))"></STextField>
                    <MTextarea Class="mt-9" @bind-Value="_model.Description"
                               Label="@T(nameof(_model.Description))"
                               Outlined
                               HideDetails="@("auto")">
                    </MTextarea>
                </AutoHeightContent>
            </AutoHeight>
        </MForm>
    </ChildContent>
    <DeleteContent Context="delete">
        @if (_entityId != default)
        {
            <MButton Class="mr-4" Icon OnClick="delete.Click">
                <SIcon Size="24" Color="error" Class="align-self-center">mdi-delete</SIcon>
            </MButton>
        }
    </DeleteContent>
    <SaveContent Context="save">
        @if (_entityId != default)
        {
            <SButton BorderRadiusClass="rounded-3" Color="fill" Class="btn-form line-primary btn primary--text" OnClick="()=> _testModal?.OpenModalAsync(_model.Id)!">@T("Test")</SButton>
        }
        <SButton BorderRadiusClass="rounded-3" Class="btn-form ml-6" OnClick="HandleOk">@T(_entityId == default?"Submit":"Save")</SButton>
    </SaveContent>
</SSimpleModal>

<WebHookTestModal @ref="_testModal" />